#include <std.h>
#include <memory.h>
#include <text.h>
#include <timer.h>
#include <irq.h>
#include <ksetting.h>

static unsigned SYSTAT_UPDATE=1;

struct systat	{
	char desc[20];
	volatile unsigned long *val;
	struct systat *next;
};

void show_systat();

static struct systat *head,*temp;

static struct timer_call *systat_timer;

void init_systat()
{
	printk("\nSystat init..");
	head=temp=NULL;
}

void init_systat_update()
{
	kernel_lock();
	systat_timer=create_timer(show_systat,SYSTAT_UPDATE);
	create_setting_val("systat_update",&SYSTAT_UPDATE);
	kernel_unlock();
}

int add_systat(char *desc,volatile unsigned long *val)
{
	if(head==NULL)	{
		head=(struct systat *)get_mem(sizeof(struct systat));
		strcpy(head->desc,desc);
		head->val=val;
		head->next=NULL;
		temp=head;
		return 0;
	}
	temp->next=(struct systat *)get_mem(sizeof(struct systat));
	temp=temp->next;
	strcpy(temp->desc,desc);
	temp->val=val;
	temp->next=NULL;
	return 0;
}	

void show_systat()
{
	unsigned short lc;
	struct systat *t;
	lc=getcursor();
	setswcursor(1520);
	text_print("-------------------------------------Status-------------------------------------");
	t=head;
	while(t)	{
		if(!(t->val))
			text_print("<%s>",t->desc);
		else
			text_print("<%s:0x%x>",t->desc,*(t->val));
		t=t->next;
	}
	setswcursor(lc);
	update_timer(systat_timer,SYSTAT_UPDATE);
}
